﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.Factory;
using ZhimeiSoft.CharmManager.Server.BLL.Interface;
using ZhimeiSoft.CharmManager.Server.DAL.Interface;

namespace ZhimeiSoft.CharmManager.Server.BLL
{
    public class ToDoListBLL : IToDoListBLL
    {
        IToDoListDAL todoListDal;
        public ToDoListBLL()
        {
            todoListDal = BaseDalFactory.CreateToDoListDal();
        }

        #region IToDoListBLL 成员

        public void InsertToDoList(DBEntityToDoList todoListInfo)
        {
            todoListDal.InsertToDoList(todoListInfo);
        }

        public void InsertResverationToDoList(DBEntityToDoList todoListInfo, DBEntityReservationToDoList reservationToDoListInfo)
        {
            todoListDal.InsertResverationToDoList(todoListInfo, reservationToDoListInfo);
        }

        public void UpdateToDoList(DBEntityToDoList todoListInfo)
        {
            if (todoListInfo.TODOSTATE == DBEntityToDoList.ENUM_TODOSTATE.T0V || todoListInfo.TODOCOMPLETIONRATE == 100)
            {
                todoListInfo.TODOCOMPLETIONRATE = 100;
                todoListInfo.TODOSTATE = DBEntityToDoList.ENUM_TODOSTATE.T0V;

            }
            todoListDal.UpdateToDoList(todoListInfo);
        }

        public void DeleteToDoList(int todoListID)
        {
            todoListDal.DeleteToDoList(todoListID);
        }

        public void DeleteResverationToDoList(DBEntityReservationToDoList reservationToDoListInfo)
        {
            todoListDal.DeleteResverationToDoList(reservationToDoListInfo);
        }

        /// <summary>
        /// 根据时间状态获取代办事项
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public DataSet GetStateToDoList(DateTime startDate, string state)
        {
            return todoListDal.GetStateToDoList(startDate, state);
        }

        public DataSet QueryTodoList(string sFilter)
        {
            return todoListDal.QueryTodoList(sFilter);
        }

        public void MarkCompleted(int todoListID)
        {
            todoListDal.MarkCompleted(todoListID);
        }

        public void CheckAllExpiredTodoState()
        {
            todoListDal.CheckAllExpiredTodoState();
        }

        /// <summary>
        /// 根据todolistID查询预约
        /// </summary>
        /// <param name="todoListID"></param>
        /// <returns></returns>
        public DataSet QueryReservationForToDoListID(int todoListID)
        {
            return todoListDal.QueryReservationForToDoListID(todoListID);
        }
        #endregion
    }
}
